<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>二当家的Lay1.0</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/static/css/x-admin.css" media="all">
<link rel="stylesheet" href="/static/lib/layui/css/layui.css"
	media="all">
</head>
<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a><cite>首页</cite></a> <a><cite>机构管理</cite></a>
			<a><cite>机构列表</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="layui-icon" style="line-height: 30px">ဂ</i></a>
	</div>
	<div class="x-body">
		<div class="layui-input-inline">
			<select id="search" class="layui-select">
				<option value="a.id">机构id</option>
				<option value="a.name">机构名称</option>
				<option value="e.name">机构类别</option>
				<option value="a.province">省份</option>
				<option value="a.city">城市</option>
				<option value="b.name">联系人</option>
				<option value="d.name">经办人</option>
			</select>
		</div>
		<div class="layui-input-inline">
			<input type="text" id="searchText" autocomplete="off"
				class="layui-input">
		</div>
		<div class="layui-input-inline" style="width: 80px">
			<button class="layui-btn" lay-submit="" lay-filter="sreach"
				onclick="searchBtn()">
				<i class="layui-icon">&#xe615;</i>
			</button>
		</div>
		<form class="layui-form " action="" style="width: 800px">
			<div class="layui-form-pane" style="margin-top: 15px;">
				<div class="layui-form-item"></div>
			</div>
		</form>
		<xblock>
		<button class="layui-btn layui-btn-danger" onclick="delAll()">
			<i class="layui-icon">&#xe640;</i>批量删除
		</button>
		<button class="layui-btn" onclick="addOrg()">
			<i class="layui-icon">&#xe608;</i>添加机构
		</button>
		<button class="layui-btn" onclick="toExcel()">导出Excel</button>
		<span class="x-right" style="line-height: 40px" id="totalSpan"></span>
		</xblock>
		<table class="layui-table">
			<thead>
				<tr>
					<th>机构编号</th>
					<th>机构名称</th>
					<th>机构类别</th>
					<th>省份</th>
					<th>城市</th>
					<th>经办人</th>
					<th>联系人</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="orgTBody">
			</tbody>
			</tbody>
		</table>
		<div class="layui-input-inline"><div id="page"></div></div>
		<div class="layui-input-inline">
			显示条数：<select id="pageSizeSelect"  style="float：right">
				<option>5</option>
				<option>10</option>
				<option>15</option>
				<option>20</option>
			</select>
		</div>
	</div>
	<script src="/static/lib/layui/layui.js" charset="utf-8"></script>
	<script src="/static/js/x-layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="/static/js/jquery.min.js"></script>
	<script>
		
		layui.use([ 'laydate', 'element', 'laypage', 'layer','form' ], function() {
			$ = layui.jquery;//jquery
			laypage = layui.laypage;//分页
			layer = layui.layer;//弹出层
			form = layui.form();
			//全选
			  form.on('checkbox(allChoose)', function(data){
			    var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
			    child.each(function(index, item){
			      item.checked = data.elem.checked;
			    });
			    form.render('checkbox');
			  });
			//分页参数设置 这些全局变量关系到分页的功能
			var currPage=1;
			var pageSize=$("#pageSizeSelect").val();
			var pages;
			//加载分页插件
			function toPage(){
				
				laypage({
					cont : 'page',
					pages : pages,
					curr : currPage,
					jump : function(obj, first) {
						currPage = obj.curr;
						if (!first) { //一定要加此判断，否则初始时会无限刷新
							loadTable();//一定要把翻页的ajax请求放到这里，不然会请求两次。
						}
					} 
				});
			}
			//ajax请求后台数据
			loadTable();
			/*模糊搜索*/
			function searchBtn() {
				loadTable();
			}
			//点击分页插件
			$("#page").click(function(){
				loadTable();
			});
			//条数下拉框改变
			$("#pageSizeSelect").change(function(){
				pageSize=$(this).val();
				currPage=1;
				loadTable();
			});
			//搜索框动态改变
			$("#searchText").keyup(function(){
				loadTable();
			});
			
			//异步加载表格
			function loadTable() {
				$
						.ajax({
							type : "post",
							dataType : "json",
							data : {
								"search" : $("#search").val(),
								"searchText" : $("#searchText").val(),
								"currPage" : currPage ,
								"pageSize" : pageSize
							},
							url : "getOListBySearch",
							type : "post",
							success : function(data) {
								$("#totalSpan").html('共有' + data.total + '条记录');
								var s = "";
								$
										.each(
												data.list,
												function(v, o) {
													s += '<tr><td>' + o.id
													+ '</td>';
													s += '<td>' + o.name + '</td>';
													s += '<td>' + o.orgKindName
															+ '</td>';
													s += '<td>' + o.province
															+ '</td>';
													s += '<td>' + o.city + '</td>';
													s += '<td>' + o.operatorNameOrg
															+ '</td>';
													s += '<td>' + o.contactName
															+ '</td>';
													s += "<td ><a title=编辑 onclick=editOrg("
															+ o.id
															+ ")> <i class=layui-icon>&#xe642;</i></a> <a title=删除 onclick=delOrg(this,"
															+ o.id
															+ ")><i class=layui-icon>&#xe640;</i> </a> <a title=详情 onclick=member_show("
															+ o.id
															+ ")> <i class=layui-icon>&#xe615;</i></td></tr>";
												});
								$("#orgTBody").html(s);
								pages=data.total/pageSize+1;
								toPage();
							}
						});
			}
		});
		
		function toExcel(){
			window.location.href="toExcel?search="+$("#search").val()+"&searchText="+$("#searchText").val();
		}
		
		//批量删除提交
		function delAll() {
			layer.confirm('确认要删除吗？', function(index) {
				//捉到所有被选中的，发异步进行删除
				layer.msg('删除成功', {
					icon : 1
				});
			});
		}

		function question_show(argument) {
			layer.msg('可以跳到前台具体问题页面', {
				icon : 1,
				time : 1000
			});
		}
		/*添加*/
		function addOrg() {
			layer.open({
				type : 2,
				title : "添加机构",
				fix : false,
				maxmin : true,
				shadeClose : true,
				area : [ "800px", "800px" ],
				content : "orgAdd",
				end : function() {
					searchBtn();
				}
			});
			x_admin_show('添加机构', 'orgAdd', '800', '800');
		}
		//编辑 
		function editOrg(id) {
			layer.open({
				type : 2,
				title : "编辑机构",
				fix : false,
				maxmin : true,
				shadeClose : true,
				area : [ "800px", "800px" ],
				content : "updateOrg?orgId=" + id,
				end : function() {
					searchBtn();
				}
			});
		}

		/*删除*/
		function delOrg(obj, id) {
			layer.confirm('确认要删除吗？', function(index) {
				$.ajax({
					data : "orgId=" + id,
					url : "delOrgAction",
					type : "post",
					success : function() {
						$(obj).parents("tr").remove();
						layer.msg('已删除!', {
							icon : 1,
							time : 1000,
						});
					}
				});
			});
		}
		
	</script>
	<script>
		var _hmt = _hmt || [];
		(function() {
			var hm = document.createElement("script");
			hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
			var s = document.getElementsByTagName("script")[0];
			s.parentNode.insertBefore(hm, s);
		})();
	</script>
</body>
</html>